<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>

<html>
<head>

<%@ include file="/WEB-INF/views/include/common.jsp"%>
<script src="${jsUrl}/jquery/flot/jquery.flot.js"></script>
<script src="${jsUrl}/jquery/flot/jquery.flot.selection.js"></script>
<script src="${jsUrl}/jquery/flot/jquery.flot.time.js"></script>
<title>chart</title>
<script type="text/javascript">
$(document).ready(function() {
	
});
var _this = this;

function weekendAreas(axes) {
	logs('axes.xaxis.min = '+axes.xaxis.min);
	logs('axes.xaxis.max = '+axes.xaxis.max);
	var markings = [],
		d = new Date(axes.xaxis.min);
	var i = d.getTime();

	do {
		markings.push({ xaxis: { from: i, to: i +  60 * 60 * 1000 } });
		i +=  60 * 60 * 1000;
	} while (i < axes.xaxis.max);

	return markings;
}
var data = [['1380071715','24'],
            ['1380071766','45'],
            ['1380071885','0'],
            ['1380072005','0'],
            ['1380072125','40'],
            ['1380072245','30'],
            ['1380072365','11'],
            ['1380072485','15'],
            ['1380072605','27'],
            ['1380072725','64'],
            ['1380072845','113'],
            ['1380072965','124'],
            ['1380073085','122'],
            ['1380073205','93'],
            ['1380073325','98'],
            ['1380073445','88'],
            ['1380073685','93'],
            ['1380073805','109'],
            ['1380073925','67'],
            ['1380074045','94'],
            ['1380074165','82'],
            ['1380074285','0'],
            ['1380074405','76'],
            ['1380074525','74'],
            ['1380074645','0'],
            ['1380074765','35'],
            ['1380074885','30'],
            ['1380075005','14'],
            ['1380075125','0'],
            ['1380075245','0'],
            ['1380075365','7'],
            ['1380075485','55'],
            ['1380075605','62'],
            ['1380075725','38'],
            ['1380075845','1'],
            ['1380085920','34'],
            ['1380086049','31'],
            ['1380086169','0'],
            ['1380086289','72'],
            ['1380086409','66'],
            ['1380086529','101'],
            ['1380086649','69'],
            ['1380086769','18'],
            ['1380086889','131'],
            ['1380087009','76'],
            ['1380087129','82'],
            ['1380087249','109'],
            ['1380087369','99'],
            ['1380087489','89'],
            ['1380087609','45'],
            ['1380087729','85'],
            ['1380087849','25'],
            ['1380087969','32'],
            ['1380088089','21'],
            ['1380088209','47'],
            ['1380088329','0'],
            ['1380088449','0'],
            ['1380088569','95'],
            ['1380113041','3'],
            ['1380113161','30'],
            ['1380113520','25'],
            ['1380113640','90'],
            ['1380113760','73'],
            ['1380113880','81'],
            ['1380114000','58'],
            ['1380114120','1'],
            ['1380114240','55'],
            ['1380114360','86'],
            ['1380114480','10'],
            ['1380114609','0'],
            ['1380114729','4'],
            ['1380114849','1'],
            ['1380114969','0'],
            ['1380115009','0']];
for (var i = 0; i < data.length; ++i) {
	data[i][0] *= 1000;
}            
function test1(){

	var d = [[1196463600000, 0], [1196550000000, 0], [1196636400000, 0], [1196722800000, 77], [1196809200000, 3636], [1196895600000, 3575], [1196982000000, 2736], [1197068400000, 1086], [1197154800000, 676], [1197241200000, 1205], [1197327600000, 906], [1197414000000, 710], [1197500400000, 639], [1197586800000, 540], [1197673200000, 435], [1197759600000, 301], [1197846000000, 575], [1197932400000, 481], [1198018800000, 591], [1198105200000, 608], [1198191600000, 459], [1198278000000, 234], [1198364400000, 1352], [1198450800000, 686], [1198537200000, 279], [1198623600000, 449], [1198710000000, 468], [1198796400000, 392], [1198882800000, 282], [1198969200000, 208], [1199055600000, 229], [1199142000000, 177], [1199228400000, 374], [1199314800000, 436], [1199401200000, 404], [1199487600000, 253], [1199574000000, 218], [1199660400000, 476], [1199746800000, 462], [1199833200000, 448], [1199919600000, 442], [1200006000000, 403], [1200092400000, 204], [1200178800000, 194], [1200265200000, 327], [1200351600000, 374], [1200438000000, 507], [1200524400000, 546], [1200610800000, 482], [1200697200000, 283], [1200783600000, 221], [1200870000000, 483], [1200956400000, 523], [1201042800000, 528], [1201129200000, 483], [1201215600000, 452], [1201302000000, 270], [1201388400000, 222], [1201474800000, 439], [1201561200000, 559], [1201647600000, 521], [1201734000000, 477], [1201820400000, 442], [1201906800000, 252], [1201993200000, 236], [1202079600000, 525], [1202166000000, 477], [1202252400000, 386], [1202338800000, 409], [1202425200000, 408], [1202511600000, 237], [1202598000000, 193], [1202684400000, 357], [1202770800000, 414], [1202857200000, 393], [1202943600000, 353], [1203030000000, 364], [1203116400000, 215], [1203202800000, 214], [1203289200000, 356], [1203375600000, 399], [1203462000000, 334], [1203548400000, 348], [1203634800000, 243], [1203721200000, 126], [1203807600000, 157], [1203894000000, 288]];

	// first correct the timestamps - they are recorded as the daily
	// midnights in UTC+0100, but Flot always displays dates in UTC
	// so we have to add one hour to hit the midnights in the plot

// 	for (var i = 0; i < d.length; ++i) {
// 		d[i][0] += 60 * 60 ;
// 	}
	
	// helper for returning the weekends in a period
	var options = {
		series: {
			lines: {
				show: true
                
			},
// 			shadowSize: 1,
			points: {
				show: true
// 				,radius:2
			}
		},
		xaxis: {
			mode: "time",
			timezone:"browser",
			tickLength: 3,
			min:data[0][0],
			max:data[data.length-1][0],
			tickDecimals: 0
		},
		legend: {
			noColumns: 1
		},
		yaxis: {
			min: 0,
			max: 150
		},
		selection: {
			mode: "x"
		},
		grid: {
			markings: weekendAreas,
			hoverable: true
			,
			color: "rgb(30, 180, 20)"
		}
		,colors:["#0000ff"]
	};

	var plot = $.plot("#placeholder", [{data:data,label:'속도'}], options);

	var overview = $.plot("#overview", [{data:data,label:'속도'}], {
		series: {
			lines: {
				show: true
				,lineWidth: 1
			},
			shadowSize: 0
		},
		xaxis: {
			ticks: [],
			mode: "time",
			timezone:"browser"
		},
		yaxis: {
			ticks: [],
			min: 0,
			autoscaleMargin: 0.1
		},
		selection: {
			mode: "x"
		}
	});
	

	// now connect the two

	$("#placeholder").bind("plotselected", function (event, ranges) {

		// do the zooming

		plot = $.plot("#placeholder", [{data:data,label:'속도'}], $.extend(true, {}, options, {
			xaxis: {
				min: ranges.xaxis.from,
				max: ranges.xaxis.to
			}
		}));

		// don't fire event on the overview to prevent eternal loop

		overview.setSelection(ranges, true);
	});

	$("#overview").bind("plotselected", function (event, ranges) {
		plot.setSelection(ranges);
	});

	// Add the Flot version string to the footer

	var previousPoint = null;
	
	$("#placeholder").bind("plothover", function (event, pos, item) {


			if (item) {
				if (previousPoint != item.dataIndex) {

					previousPoint = item.dataIndex;

					$("#tooltip").remove();
					var x = item.datapoint[0].toFixed(2),
					y = item.datapoint[1].toFixed(2);
// 					+item.series.label
					showTooltip(item.pageX, item.pageY,
							formatter.timeFormatHHMMSS2nd(new Date(x*1))+"-"+ y+"km");
				}
			} else {
				$("#tooltip").remove();
				previousPoint = null;            
			}
	});

}
function test2(){

}
function showTooltip(x, y, contents) {
	$("<div id='tooltip'>" + contents + "</div>").css({
		position: "absolute",
		display: "none",
		top: y + 5,
		left: x + 5,
		border: "1px solid #fdd",
		padding: "2px",
		"background-color": "#fee",
		opacity: 0.80
	}).appendTo("body").fadeIn(200);
}
function test3(){
	
}
function test4(){
	
}
function test5(){
	
}
</script>
</head>
<body >
	<ul>
		<li><input type="button" value="chart1" onclick="test1()" /></li>
		<li><input type="button" value="chart2" onclick="test2()" /></li>
		<li><input type="button" value="test3" onclick="test3()" /></li>
		<li><input type="button" value="test4" onclick="test4()" /></li>
		<li><input type="button" value="test5" onclick="test5()" /></li>
	</ul>
	<div id="placeholder" style="width:850px;height:400px;"></div>
	<div id="overview" style="width:850px;height:150px;"></div>	
</body>
</html>


